package cn.cxy.demo.common

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import cn.cxy.demo.R
import kotlinx.android.synthetic.main.fragment_progress_dialog.*

class ProgressDialogFragment : DialogFragment() {

    companion object {
        fun newInstance() =
                ProgressDialogFragment()
    }

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_progress_dialog, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        messageTv.text = "加载中..."
    }

    fun show(
            fragmentManager: FragmentManager,
            @StringRes messageResId: Int,
            isCancelable: Boolean = false
    ) {
        this.isCancelable = isCancelable
        show(fragmentManager, "progressDialogFragment")
    }

}